package reposit

import (
	"errors"
	"github.com/jinzhu/gorm"
	"sbd_nydjz/inits"
	"sbd_nydjz/models"
)

type GasterReposit struct {
	Db inits.Database
}

func (repo *GasterReposit) IsGasterOne(code string) (bool, error) {
	db := repo.Db.DB
	isGaster := &models.Djzinfo{}
	if !errors.Is(db.Raw("select * from djzinfo where djzh=?", code).Scan(&isGaster).Error, gorm.ErrRecordNotFound) {
		return false, errors.New("登记证号已存在！")
	}
	return true, nil
}
func (repo *GasterReposit) InsertGasterOne(gaster models.Djzinfo) (bool, error) {
	db := repo.Db.DB
	err := db.Table("djzinfo").Create(gaster).Error

	if err != nil {
		return false, errors.New("添加 农药登记证 失败")
	}
	return true, nil
}
